package com.distributed.common.message;

import net.sf.json.JSONObject;

import com.distributed.common.Constant;

public class LeaveNotifyMessage extends BaseMessage {
	
	public LeaveNotifyMessage() {
		super();
		setId(Constant.LEAVE_NOTIFY_MESSAGE);
	}

	public LeaveNotifyMessage(String username) {
		this();
		setLeaveUser(username);
	}
	
	public static String getName() {
		return Constant.LEAVE_NOTIFY_MESSAGE_NAME;
	}

	public void setLeaveUser(String username) {
		argv.put(Constant.LEAVE_USER_NAME, username);
	}
	
	public String getLeaveUser() {
		return argv.get(Constant.LEAVE_USER_NAME);
	}
	
	public static LeaveNotifyMessage getFromString(String message) {
		JSONObject jsonobject = JSONObject.fromObject(message);
		if (jsonobject == null) {
			return null;
		}
		return getFromJSON(jsonobject);
	}

	public static LeaveNotifyMessage getFromJSON(JSONObject jsonobj) {
		BaseMessage baseMessage = new LeaveNotifyMessage();
		BaseMessage baseMsg = BaseMessage.getFromJSON(jsonobj, baseMessage);
		if (baseMsg == null || baseMsg.getId() != Constant.LEAVE_NOTIFY_MESSAGE) {
			return null;
		}
		
		return (LeaveNotifyMessage) baseMsg;
	}

	public JSONObject toJSON() {
		return super.toJSON();
	}
	
	public String toString() {
		return toJSON().toString();
	}
}
